package com.bqtt.tumor.demo.entity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.bqtt.tumor.demo.business.BodyPartService;
import com.bqtt.tumor.demo.business.FeatureService;
import com.bqtt.tumor.demo.business.TreatmentMethodService;
import com.bqtt.tumor.demo.common.utility.InlineTools;
import com.bqtt.tumor.demo.presentation.model.desease.DCharacter;


@Entity
@Table(name="desease_def") 
public class Desease  implements IDBEntity{

	@Id 
    @Column(name="desease_def_id")    
    @GeneratedValue(strategy=GenerationType.IDENTITY) 
	private int desease_def_id;
	
	@Column(name = "desease_code", length= 25)
	private String desease_code;
	
	@Column(name = "desease_name", length= 255)
	private String desease_name;
	
	@Column(name = "desease_english_name", length= 255)
	private String desease_english_name;
	
	@Column(name = "clinic_feature", length= 1500)
	private String clinic_feature;
	
	@Column(name = "characters", length= 6)
	private String characters;
	
	@Column(name = "related_part_code")
	private int related_part_code;
	
	@Column(name = "treatment_methods", length= 1000)
	private String treatment_methods;

	@Transient
	private String displayName;
	
	@Transient
	private String related_part_string; 
	
	// 临床特征
	@Transient
	private List<Feature> clinic_list;
	
	//性状特征
	@Transient
	private List<DCharacter> charactor_list;
	
	//治疗方法
	@Transient
	private List<TreatmentMethod> treatment_method_list;
	
	

	public Desease() {
		super();
		displayName ="none";
		characters ="00000";
		clinic_feature="";
		treatment_methods="";
		// TODO Auto-generated constructor stub
	}
	public Desease(int i) {
		super();
		displayName ="none";
		characters ="00000";
		clinic_feature="";
		treatment_methods="";
		fillStringField();
		// TODO Auto-generated constructor stub
	}

	@Override
	public Map<String, Object> getSQLValidAttributes() {
		// TODO Auto-generated method stub
		
		Map<String,Object> result = new HashMap<String,Object>();
		
		if(!InlineTools.isEmpty(desease_code))
		{
			result.put("desease_code", desease_code);
		}
		
		if(!InlineTools.isEmpty(desease_name))
		{
			result.put("desease_name", desease_name);
		}
		return result;
	}

	@Override
	public void fillStringField() {
		// TODO Auto-generated method stub
		List<Feature> featureList = FeatureService.getList(1,0);
		//临床特征填充
		if(!InlineTools.isEmpty(clinic_feature))
		{
			String [] array = clinic_feature.split("\\|");
			for(Feature item: featureList)
			{
				if(InlineTools.containsItem(array, item.getFeature_id()+""))
				{
					item.setChecked(InlineTools.checkedStyle);
				}
				else
				{
					item.setChecked(InlineTools.nocheckedStyle);
				}
			}
		}
		else
		{
			for(Feature item: featureList)
			{
					item.setChecked(InlineTools.nocheckedStyle);
			}
		}
		setClinic_list(featureList);
		List<DCharacter> characterList = new ArrayList<DCharacter>();
		//性状特征
		if(!InlineTools.isEmpty(characters) || characters.length()==5)
		{
		    if(characters.charAt(0)=='0')
		    	characterList.add(new DCharacter(1,"原发性",InlineTools.nocheckedStyle));
		    else
		    	characterList.add(new DCharacter(1,"原发性",InlineTools.checkedStyle));
		    
		    if(characters.charAt(1)=='0')
		    	characterList.add(new DCharacter(2,"继发性",InlineTools.nocheckedStyle));
		    else
		    	characterList.add(new DCharacter(2,"继发性",InlineTools.checkedStyle));
		    
		    if(characters.charAt(2)=='0')
		    	characterList.add(new DCharacter(3,"转移性",InlineTools.nocheckedStyle));
		    else
		    	characterList.add(new DCharacter(3,"转移性",InlineTools.checkedStyle));
		    
		    if(characters.charAt(3)=='0')
		    	characterList.add(new DCharacter(4,"遗传性",InlineTools.nocheckedStyle));
		    else
		    	characterList.add(new DCharacter(4,"遗传性",InlineTools.checkedStyle));
		    
		    if(characters.charAt(4)=='0')
		    	characterList.add(new DCharacter(5,"是否良性",InlineTools.nocheckedStyle));
		    else
		    	characterList.add(new DCharacter(5,"是否良性",InlineTools.checkedStyle));
		    
		}
		
		setCharactor_list(characterList);
		List<TreatmentMethod> treatmentMethodList = TreatmentMethodService.getList();
		//治疗方法特征
		if(!InlineTools.isEmpty(treatment_methods))
		{
			String [] array = treatment_methods.split("\\|");
			for(TreatmentMethod item: treatmentMethodList)
			{
				if(InlineTools.containsItem(array, item.getTreatment_method_def_id()+""))
				{
					item.setChecked(InlineTools.checkedStyle);
				}
				else
				{
					item.setChecked(InlineTools.nocheckedStyle);
				}
			}
		}
		else
		{
			for(TreatmentMethod item: treatmentMethodList)
			{
					item.setChecked(InlineTools.nocheckedStyle);
			}
		}
		setTreatment_method_list(treatmentMethodList);
	
		if(related_part_code>0)
		{
			related_part_string = BodyPartService.getNameByCode(related_part_code);
		}
		 
	}

	@Override
	public void fillDBfields() {
		// TODO Auto-generated method stub
		
	}
	public int getDesease_def_id() {
		return desease_def_id;
	}
	public void setDesease_def_id(int desease_def_id) {
		this.desease_def_id = desease_def_id;
	}
	public String getDesease_code() {
		return desease_code;
	}
	public void setDesease_code(String desease_code) {
		this.desease_code = desease_code;
	}
	public String getDesease_name() {
		return desease_name;
	}
	public void setDesease_name(String desease_name) {
		this.desease_name = desease_name;
	}
	public String getDesease_english_name() {
		return desease_english_name;
	}
	public void setDesease_english_name(String desease_english_name) {
		this.desease_english_name = desease_english_name;
	}
	public String getClinic_feature() {
		return clinic_feature;
	}
	public void setClinic_feature(String clinic_feature) {
		this.clinic_feature = clinic_feature;
	}
	public String getCharacters() {
		return characters;
	}
	public void setCharacters(String characters) {
		this.characters = characters;
	}
	public int getRelated_part_code() {
		return related_part_code;
	}
	public void setRelated_part_code(int related_part_code) {
		this.related_part_code = related_part_code;
	}
	public String getTreatment_methods() {
		return treatment_methods;
	}
	public void setTreatment_methods(String treatment_methods) {
		this.treatment_methods = treatment_methods;
	}
	public String getDisplayName() {
		return displayName;
	}
	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}
	public String getRelated_part_string() {
		return related_part_string;
	}
	public void setRelated_part_string(String related_part_string) {
		this.related_part_string = related_part_string;
	}
	public List<Feature> getClinic_list() {
		return clinic_list;
	}
	public void setClinic_list(List<Feature> clinic_list) {
		this.clinic_list = clinic_list;
	}
	public List<DCharacter> getCharactor_list() {
		return charactor_list;
	}
	public void setCharactor_list(List<DCharacter> charactor_list) {
		this.charactor_list = charactor_list;
	}
	public List<TreatmentMethod> getTreatment_method_list() {
		return treatment_method_list;
	}
	public void setTreatment_method_list(List<TreatmentMethod> treatment_method_list) {
		this.treatment_method_list = treatment_method_list;
	}

	
	
	
	
}
